from comm.loadsave import loadData, saveData
from comm.ui import Panel, ItemList, StatePanel
from comm.style import *
from ship import Ship
import time, os

path = "data/"
filename = "gameData.json"
file = path + filename

os.system("")

class Ship():
    def __init__(self,shipdata) -> None:
        self.id     = shipdata[0]
        self.name   = shipdata[1]
        self.type   = shipdata[2]
        self.enage   = shipdata[3]
        self.vel   = shipdata[4]
        self.jumpVel  = shipdata[5]
        self.cap   = shipdata[6]
        self.out   = shipdata[7]
        self.mid   = shipdata[8]
        self.core   = shipdata[9]
        self.shield   = shipdata[10]
        self.armor   = shipdata[11]
        self.hull   = shipdata[12]
        self.shieldRecovery   = shipdata[13]


# 测试颜色
def test_style():
    s_moveto(1,1)
    print(s_bgblack + ' '* 5, s_lbgblack + ' '* 5)
    print(s_bgred + ' '* 5, s_lbgred + ' '* 5) 
    print(s_bggreen+ ' '* 5, s_lbggreen+ ' '* 5) 
    print(s_bgyellow + ' '* 5, s_lbgyellow + ' '* 5) 
    print(s_bgblue + ' '* 5,s_lbgblue + ' '* 5) 
    print(s_bgpurple + ' '* 5, s_lbgpurple + ' '* 5) 
    print(s_bggrass + ' '* 5, s_lbggrass + ' '* 5) 
    print(s_bgwhite + ' '* 5, s_lbgwhite + ' '* 5)

# 测试内容载入保存功能
def test_loadsave(file):
    # 总数据入口
    data = loadData(file)
    gameData = data['gameData']
    # 静态数据:飞船
    shipsData= data['ships']
    # 动态数据: 玩家
    playerData = data['player']
    # 玩家--> 当前飞船
    activeShip = playerData['activeShip']
    activeShipId = activeShip['id']
    activeShipName = activeShip['activeName']
    myship = Ship(shipsData[activeShipId])

    playerData['activeShip']['activeName'] = "保命龟"
    playerData['activeShip']['id'] = 0
    # show info
    print("当前激活飞船:", activeShipName, myship.name, myship.type)

    # 保存动态数据
    saveData(file, gameData, playerData)


# 测试界面功能(Panel)
def test_ui_panel():
    s_clean()
    p = Panel()
    p.titleBg = s_bgred     # 红色标题, 余同
    p.titleColor = s_black
    p.title = '开始隐藏'
    print(p.refresh())
    # 测试隐藏
    time.sleep(1)
    s_clean()
    p.hide()
    p.title = '开始显示'
    print(p.refresh())
    # 测试显示
    time.sleep(1)
    s_clean()
    p.show()
    p.title = '开始移动'
    print(p.refresh())
    # 测试移动
    time.sleep(1)
    s_clean()
    p.moveto(5,5)
    p.title = '结束演示'
    print(p.refresh())


# 测试界面样式(Panel)
def test_ui_itemlist(ship):
    # 灰白
    p1 = ItemList(ship) 

    print(p1.refresh())

 # 测试飞船状态面板
def test_statePanel(ship):
    sp = StatePanel(ship)
    print(sp.refresh())



if __name__=='__main__':   
    test_loadsave(file)

    input()
